﻿
@{
    ViewData["Title"] = "Show";
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <script src="~/libs/jquery/jquery.js"></script>
    <link href="~/layui-v2.9.16/layui/css/layui.css" rel="stylesheet" />
    <script src="~/layui-v2.9.16/layui/layui.js"></script>
</head>
<body>

    <form class="layui-form layui-row layui-col-space14 layui-inline">


        <div class="layui-form-item layui-inline">
            <label class="layui-form-label">移库单号</label>
            <div class="layui-input-wrap layui-input-inline">
                <input type="text" name="TransferCode" value="" placeholder="移库单号" class="layui-input" lay-affix="clear" id="TransferCode">
            </div>
        </div>

        <div class="layui-form-item layui-inline">
            <label class="layui-form-label">移库类型</label>
            <div class="layui-input-wrap layui-input-inline">
                <select name="TransferType" lay-filter="TransferType" id="TransferType">
                    <option value="0">请选择</option>
                    <option value="移库上架">移库上架</option>
                    <option value="仓库移库">仓库移库</option>
                    <option value="报损移库">报损移库</option>
                </select>
            </div>
        </div>


        <div class="layui-btn-container layui-inline">
            <button type="button" class="layui-btn" id="workshops">查询</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>

    </form>

    <script type="text/html" id="toolbarDemo">
        <div class="layui-btn-container">
          <button type="submit" class="layui-btn layui-bg-blue" lay-submit lay-filter="demoAdd">添加</button>
        </div>
    </script>



    <table class="layui-hide" lay-filter="test" id="ID-table-demo-page"></table>



    <script type="text/html" id="toolDemo">
        <div class="layui-clear-space">
          <a class="layui-btn layui-btn-xs" lay-event="edits">修改</a>
          <a class="layui-btn layui-btn-xs" lay-event="del">删除</a>
        </div>
    </script>

    <script>
        layui.use(['laydate', 'table', 'form', 'dropdown'], function () {
            var table = layui.table;
            var form = layui.form;
            var field = layui.field;
            var laydate = layui.laydate;
            var dropdown = layui.dropdown;
            // 日期
            laydate.render({
                elem: '#recptDate'
            });

            //显示
            function GetTransfer() {
                var TransferCode = $("#TransferCode").val();
                var TransferType = $("#TransferType").val();
                // 创建渲染实例
                table.render({
                    elem: '#ID-table-demo-page',
                    toolbar: '#toolbarDemo',
                    url: '/TransferController1/GetTransfer', // 此处为静态模拟数据，实际使用时需换成真实接口
                    where: {
                        TransferCode: TransferCode,
                        TransferType: TransferType,
                    },
                    cols: [[
                        { type: 'checkbox', fixed: 'left' },
                        { field: 'transferCode', width: 150, title: '移库单号', sort: true },
                        { field: 'transferType', width: 150, title: '移库单类型', sort: true },
                        { field: 'productCode', width: 150, title: '产品编号' },
                        { field: 'productSpecification', width: 150, title: '产品规格' },
                        { field: 'unit', width: 150, title: '单位' },
                        { field: 'unitPrice', width: 150, title: '单价' },
                        { field: 'quantity', width: 150, title: '数量' },
                        {
                            field: 'unitPrice', width: 150, title: '总额', templet: function (row) {
                                var UnitPrice = row.unitPrice * row.quantity;
                                return UnitPrice;
                             } 
                        },
                        { field: 'maker', width: 150, title: '制单人', sort: true },
                        {
                            field: 'maker', width: 150, title: '制单时间', templet: function (row) {
                                var maker = row.maker.split("T")[0]
                                return maker;
                            }
                        },
                        {field: 'right', width: 200, title: '操作', templet: '#toolDemo'}
                    ]],
                    //分页
                    page: {
                        limit: 10,
                        limits: [10, 15, 20, 25],
                        prev: '上一页',
                        next: '下一页',
                        first: '首页',
                        last: '尾页'
                    },
                    request: {
                        pageName: 'pageindex',
                        limitName: 'pagesize'
                    },
                    parseData: function (res) {
                        console.log(res)
                        return {
                            "code": res.code, //解析接口状态
                            "count": res.listcount, //解析数据长度
                            "data": res.list//解析数据列表

                        };
                    },

                });

            }

            GetTransfer();

            //显示
            $("#workshops").on("click", function () {//查询
                GetTransfer();
            })

            //弹出
            form.on('submit(demoAdd)', function () {
                layer.open({
                    type: 2, // page 层类型
                    area: ['80%', '80%'],
                    title: '新增销售订单',
                    shade: 0.6, // 遮罩透明度
                    shadeClose: true, // 点击遮罩区域，关闭弹层
                    maxmin: true, // 允许全屏最小化
                    anim: 0, // 0-6 的动画形式，-1 不开启
                    content: '/TransferController1/Add',
                    end: function () {

                        GetTransfer();//刷新父级页面列表方法，类似于回调函数
                    }
                });
            })



            //表单操作
            table.on('tool(test)', function (obj) {
                var data = obj.data; // 获得当前行数据
                var listwork = data;
                console.log(listwork)
                localStorage.setItem("TransferList",JSON.stringify(listwork));

                if (obj.event === 'edits') {
                    layer.open({
                        title: '编辑',
                        type: 2,
                        area: ['80%', '80%'],
                        content: '/TransferController1/Update',
                        end: function () {

                            GetTransfer();//刷新父级页面列表方法，类似于回调函数
                    }
                    });
                }

                else if (obj.event === 'del') {

                    layer.confirm('确定要删除吗？', function (index) {
                        $.ajax({
                            url: '/TransferController1/DeletesTransfer',
                            type: 'Get',
                            data: { Id: data.productCode },
                            dataType: 'json',
                            success: function (res) {
                                layer.msg("删除成功");
                                GetTransfer();
                            }
                        })
                        layer.close(index);
                        // 向服务端发送删除指令
                    });

                }



            });


        });



    </script>

</body>
</html>



